﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Item;
using Item.Buff;

namespace Player.Fort
{
    public class FortNode : MonoBehaviour
    {
        public event System.Action<ST_ItemBuffData[]> EventOnBuffChange;

        public Vector2Int vIndex;

        public bool HaveItem => CurItem != null;
        public ItemBase CurItem { get; private set; } = null;

        [ReadOnly,SerializeField]
        private List<ST_ItemBuffData> listBuff = new List<ST_ItemBuffData>();
        public ST_ItemBuffData[] Buffs => listBuff.ToArray();

        public void Equip(ItemBase item)
        {
            //如果是同一个道具，就重新初始化一下
            if ((item != null && !HaveItem) || item == CurItem)
            {
                item.transform.position = transform.position;
                CurItem = item;
            }
        }
        public void CancelEquip(ItemBase item)
        {
            if (HaveItem && CurItem == item)
            {
                CurItem = null;
            }
        }

        public void AddBuff(ST_ItemBuffData[] buffDatas)
        {
            listBuff.AddRange(buffDatas);

            EventOnBuffChange?.Invoke(Buffs);
        }
        public void RemoveBuff(string guid)
        {
            listBuff.RemoveAll((data) => data.strGUID == guid);

            EventOnBuffChange?.Invoke(Buffs);
        }
    }
}